/*
 *  meanshift.h
 *  Woochy
 *
 *  Created by MiGi on 11/26/09.
 *  Copyright 2009 OSU. All rights reserved.
 *
 */
#include "cv.h"
#include "highgui.h"

class MeanShift {
    
    IplImage *hsv, *hue, *mask, *backproject, *histimg;
    CvHistogram *hist;
    int vmin, vmax, smin;  
    float* hranges;
    CvRect track_window;   
    CvConnectedComp comp;    
public:    
    bool initialized;

    MeanShift( CvSize size) ;
    bool init(IplImage *image, const CvRect &selection) ;
    bool run(IplImage *image);

    
    CvScalar hsv2rgb(float hue)   
    {   
        int rgb[3], p, sector;   
        static const int sector_data[][3]=   
        {{0,2,1}, {1,2,0}, {1,0,2}, {2,0,1}, {2,1,0}, {0,1,2}};   
        hue *= 0.033333333333333333333333333333333f;   
        sector = cvFloor(hue);   
        p = cvRound(255*(hue - sector));   
        p ^= sector & 1 ? 255 : 0;   
        
        rgb[sector_data[sector][0]] = 255;   
        rgb[sector_data[sector][1]] = 0;   
        rgb[sector_data[sector][2]] = p;   
        
        return cvScalar(rgb[2], rgb[1], rgb[0],0);   
        
    }   
};
